<template>
  <div class="app-container">
    <el-form
      class="el-forms"
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <div class="handle_box_content" ref="handle_box_content">
        <el-form-item label="姓名" prop="userName" class="custom-form-item">
          <el-input
            v-model="queryParams.userName"
            placeholder="请输入姓名"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="身份证" prop="userCode" class="custom-form-item">
          <el-input
            v-model="queryParams.userCode"
            placeholder="请输入身份证号码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="学历" prop="userEdu" class="custom-form-item">
          <el-select v-model="queryParams.userEdu" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="时间选择"
          prop="createTimes"
          class="custom-form-item"
        >
          <el-date-picker
            class="handle_picker"
            v-model="queryParams.createTimes"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            range-separator="至"
            start-placeholder="创建时间"
            end-placeholder="结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="工作地址" prop="userWork" class="custom-form-item">
          <el-input
            v-model="queryParams.userWork"
            placeholder="请输入工作地址"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          plain
          size="mini"
          :icon="Showbox ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
          @click="handleShow"
          >{{ Showbox ? "隐藏" : "展开" }}</el-button
        >
      </el-form-item>
    </el-form>
    <span>{{ crumbs }}</span>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:bizuser:add']"
          >新增</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:bizuser:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:bizuser:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:bizuser:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="userList"
      @selection-change="handleSelectionChange"
      size="mini"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="主键ID" align="center" prop="id" v-if="true"/>-->
      <el-table-column label="姓名" align="center" prop="userName" />
      <el-table-column label="身份证号码" align="center" prop="userCode" />
      <el-table-column label="年龄" align="center" prop="userAge" />
      <el-table-column label="学历" align="center" prop="userEdu" />
      <el-table-column label="家庭住址" align="center" prop="userHome" />
      <el-table-column label="工作地址" align="center" prop="userWork" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy" />
      <el-table-column
        label="更新时间"
        align="center"
        prop="updateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:bizuser:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:bizuser:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {
  listUser,
  getUser,
  delUser,
  addUser,
  updateUser,
} from "@/api/system/bizuser";
import Breadcrumb from "@/components/Breadcrumb/index";
// import importScss from "../../../assets/styles/component.scss"
export default {
  name: "User",
  components: {
    Breadcrumb,
  },
  data() {
    return {
      Showbox: false,
      crumbs: undefined,
      options: [
        {
          value: "小学",
          label: "小学",
        },
        {
          value: "中学",
          label: "中学",
        },
        {
          value: "大学",
          label: "大学",
        },
      ],
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 业务用户表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      flowId: 1,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        userCode: undefined,
        userAge: undefined,
        userEdu: undefined,
        userHome: undefined,
        userWork: undefined,
        createBy: undefined,
        createTime: null,
        createTimes: null,
        updateBy: undefined,
        updateTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ID: [{ required: true, message: "主键ID不能为空", trigger: "blur" }],
        userName: [
          { required: true, message: "姓名不能为空", trigger: "blur" },
        ],
        userCode: [
          { required: true, message: "身份证号码不能为空", trigger: "blur" },
        ],
        userAge: [{ required: true, message: "年龄不能为空", trigger: "blur" }],
        userEdu: [{ required: true, message: "学历不能为空", trigger: "blur" }],
        userHome: [
          { required: true, message: "家庭住址不能为空", trigger: "blur" },
        ],
        userWork: [
          { required: true, message: "工作地址不能为空", trigger: "blur" },
        ],
        createBy: [
          { required: true, message: "创建人不能为空", trigger: "blur" },
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" },
        ],
        updateBy: [
          { required: true, message: "更新人不能为空", trigger: "blur" },
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    open() {
      this.peopleOpen = true;
    },
    //选择人的确定按钮事件 submitPeople(nikeNamelist)方法传参一个默认接收用户昵称数组   submitPeople(peopleList,nikeNamelist)方法传参两个则是接收用户昵称数组和用户账号数组
    submitPeople(peopleList) {
     // console.log(peopleList);
      this.peopleOpen = false;
    },
    //搜索框的展示隐藏
    handleShow() {
      this.Showbox = !this.Showbox;
      const element = this.$refs.handle_box_content;
      if (this.Showbox) {
        element.style.overflow = "visible";
        element.style.height = "fit-content";
      } else {
        element.style.overflow = "hidden";
        element.style.height = "50px";
      }
    },
    /** 查询业务用户列表 */
    getList() {
      this.crumbs = this.$route.matched.map((route) => ({
        name: route.meta.title, // 面包屑名称
        path: route.path, // 面包屑路径
      }));
      var lastObject = this.crumbs[this.crumbs.length - 1];
      this.crumbs = lastObject.name;

      this.loading = true;
      //console.log(this.queryParams);
      listUser(this.queryParams).then((response) => {
        this.userList = response.rows;
        //console.log(this.userList);
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ID: undefined,
        userName: undefined,
        userCode: undefined,
        userAge: undefined,
        userEdu: undefined,
        userHome: undefined,
        userWork: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      //console.log(selection.map((item) => item.id));
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push("/pageView/formDialog");
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$router.push({
        path: "/pageView/formDialog",
        query: { ID: row.id, IDS: this.ids, flowId: this.flowId },
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id !== undefined) {
            updateUser(this.form)
              .then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          } else {
            addUser(this.form)
              .then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除业务用户编号为"' + IDs + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delUser(IDs);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/user/export",
        {
          ...this.queryParams,
        },
        `user_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style scoped lang="scss">
.handle_box_content {
  width: 80%;
  height: 50px;
  overflow: hidden;
}

.el-date-editor--datetimerange.el-input,
.el-date-editor--datetimerange.el-input__inner {
  width: 250px !important;
}
.el-forms {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
}
</style>
